// -----------------------------------------------------------------------
//  <copyright file="RemoveResourceCacheCommand.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/8 18:26</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Domain.IntegrationEvents;

namespace DaprPlus.Authorization.Application.Commands;

public class RemoveResourceCacheCommand : IRequest<bool>
{
    public required ResourceIntegrationEventDto[] Dtos { get; set; }
}

public class RemoveResourceCacheCommandHandler(IAuthorizationCache cache) : IRequestHandler<RemoveResourceCacheCommand, bool>
{
    public async Task<bool> Handle(RemoveResourceCacheCommand request, CancellationToken cancellationToken)
    {
        foreach (var dto in request.Dtos)
        {
            await cache.RemoveResourceCache(dto.Code, dto.Type);
        }
        return true;
    }
}
